<template>
  <div class="order-detail">
    <div class="detail-title">
      <el-button type="primary" icon="el-icon-back">{{$t("orderManage.returntothesuperior")}}</el-button>
    </div>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="360px">
        <div class="info-title">{{$t("orderManage.essentialinformation")}}</div>
        <div style="padding: 20px 24px 20px 0;margin-bottom: 40px;">
        <el-form ref="form" :model="form" label-width="96px" size="small">
          <el-form-item :label="$t('orderManage.ordertimt')">
            <el-input v-model="form.orderTime"></el-input>
          </el-form-item>
          <el-form-item :label="$t('orderManage.numberofdiners')">
            <el-input v-model="form.personNum"></el-input>
          </el-form-item>
          <el-form-item :label="$t('orderManage.servicepersonal')">
            <el-select style="width: 239px;" v-model="form.waiter" :placeholder="$t('orderManage.pleaseservice')">
              <el-option
                v-for="item in waiterList"
                :key="item.uid+'a'"
                :label="item.nick_name"
                :value="item.uid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('orderManage.remarkss')">
            <el-input type="textarea" v-model="form.desc"></el-input>
          </el-form-item>
        </el-form>
        </div>
        <div class="info-title">{{$t("orderManage.settlementinformation")}}
          <div class="paid-title">{{$t("orderManage.Settled")}}</div>
          <div class="unpaid-title">
          {{$t("orderManage.surplus")}}   <span>€ 528.36</span> {{$t("orderManage.uncleared")}}
          </div>
        </div>
        <div style="padding: 20px 24px 20px 0;margin-bottom: 40px;">
          <el-form ref="form" :model="form" label-width="96px" size="small">
            <el-form-item  :label="$t('orderManage.grosssettlement')">
              <el-input v-model="form.orderTime"></el-input>
            </el-form-item>
            <el-form-item :label="$t('orderManage.Discount')">
              <el-input v-model="form.personNum"></el-input>
            </el-form-item>
          </el-form>
          <el-tabs v-model="editableTabsValue2" @tab-remove="removeTab">
            <el-tab-pane
              v-for="(item,indexs) in editableTabs2"
              :key="indexs"
              :label="item.title"
              :name="item.name"
            >
              <el-form ref="form" :model="form" label-width="96px" size="small">
                <el-form-item :label="$t('orderManage.creditCardsAccepted')">
                  <el-input v-model="form.orderTime"></el-input>
                </el-form-item>
                <el-form-item :label="$t('orderManage.bankcardpayment')">
                  <el-input v-model="form.personNum"></el-input>
                </el-form-item>
                <el-form-item :label="$t('orderManage.cashpayment')">
                  <el-input v-model="form.personNum"></el-input>
                </el-form-item>
              </el-form>
            </el-tab-pane>
          </el-tabs>
          <div class="add-pay-btn">
            <el-button type="primary" @click="addTab(editableTabsValue2)">新增结算</el-button>
          </div>
        </div>
      </el-aside>
      <el-main>
        <div class="info-title">{{$t('orderManage.menuinformation')}}
          <div class="total-title">
            {{$t('orderManage.total')}} <span>€ 528.36</span>
          </div>
        </div>
        <el-table
          :data="orderData"
          stripe
          border
          style="width: 100%">
          <el-table-column
            prop="date"
            :label="$t('orderManage.creditCardsAccepted')"
            width="180">
          </el-table-column>
          <el-table-column
            prop="num"
            :label="$t('orderManage.nambers')"
            width="180">
            <template slot-scope="scope">
              <el-input-number size="mini" v-model="scope.row.num"></el-input-number>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            :label="$t('orderManage.name')"

            width="180">
          </el-table-column>
          <el-table-column
            prop="address"
            :label="$t('orderManage.address')"
>
          </el-table-column>
        </el-table>
        <div style="margin: 20px 0;text-align: center">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page.num"
            :page-sizes="page.sizes"
            :page-size="page.size"
            :total="page.total"
            layout="sizes, prev, pager, next">
          </el-pagination>
        </div>
        <div style="float: right">
          <el-button>{{$t("orderManage.savechanges")}}</el-button>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
  export default {
    name: 'OrderDetail',

    data() {
      return {
        orderId: '', // 订单id
        form: {
          orderTime: '',
          waiter: '',
          personNum: '',
          desc: ''
        },
        activeName: 'second',
        editableTabsValue2: '2',
        editableTabs2: [{
          title: 'Tab 1',
          name: '1',
          content: 'Tab 1 content'
        }, {
          title: 'Tab 2',
          name: '2',
          content: 'Tab 2 content'
        }],
        tabIndex: 2,
        orderData: [],  // 订单详情
        orderPayRec: [], // 订单结算记录
        waiterList: [], // 服务人员列表
        page: {
          num: 1, // 分页页码
          size: 10, // 分页条数
          sizes: [10, 20, 50, 100], // 条数选择
          total: 0 // 总条数
        }
      }
    },

    props: {},

    components: {},

    mounted() {
      this.orderId = this.$route.params.id
      // 获取订单详情
      this.getOrderDetail()
      // 获取订单结算记录
      this.getOrderPayRec()
      // 获取服务员列表
      this.getWaiterList()
    },

    watch: {},

    computed: {},

    filters: {},

    methods: {
      // 获取订单详情
      getOrderDetail() {
        this.$axios.get(`${this.$REQ_URL}app&action=order_info&order_id=${this.orderId}`).then(res => {
          if (res.data.state === 1) {
            this.orderData = res.data.data
          } else if (res.data.state === -1) {
            this.$message.info(res.data.msg)
          }
        })
      },

      // 获取订单结算记录
      getOrderPayRec() {
        this.$axios.post(`${this.$REQ_URL}app&action=paylog`, {
          order_id: this.orderId
        }).then(res => {
          if (res.data.state === 1) {
            this.orderPayRec = res.data.data
          }
        })
      },

      // 获取服务人员列表
      getWaiterList() {
        this.$axios.get(`${this.$REQ_URL}app&action=member_list&shopid=${sessionStorage.getItem('shopId')}`).then(res => {
          if (res.data.state === 1) {
            this.waiterList = res.data.data
          }
        })
      },

      addTab(targetName) {
        let newTabName = ++this.tabIndex + ''
        this.editableTabs2.push({
          title: 'New Tab',
          name: newTabName,
          content: 'New Tab content'
        })
        this.editableTabsValue2 = newTabName
      },
      removeTab(targetName) {
        let tabs = this.editableTabs2
        let activeName = this.editableTabsValue2
        if (activeName === targetName) {
          tabs.forEach((tab, index) => {
            if (tab.name === targetName) {
              let nextTab = tabs[index + 1] || tabs[index - 1]
              if (nextTab) {
                activeName = nextTab.name
              }
            }
          })
        }

        this.editableTabsValue2 = activeName
        this.editableTabs2 = tabs.filter(({ name }) => name !== targetName)
      },

      // 选择每页显示多少条数据
      handleSizeChange (size) {
        this.page.size = size
        this.getGoods(this.goodsType[this.activeIndex], this.activeIndex)
      },

      // 选择第几页数据
      handleCurrentChange (page) {
        this.page.num = page
        this.getGoods(this.goodsType[this.activeIndex], this.activeIndex)
      }
    }
  }
</script>

<style scoped>
  .order-detail {
    background: #ffffff;
    box-shadow: 0 3px 10px 0 rgba(0, 0, 0, 0.10);
    padding: 0 40px;
    margin-bottom: 80px;
  }

  .detail-title {
    background: #ffffff;
    height: 80px;
    line-height: 80px;
    border-bottom: 1px solid #dedede;
  }

  .el-aside {
    overflow: hidden;
    box-sizing: border-box;
    -moz-box-sizing: border-box; /* Firefox */
    -webkit-box-sizing: border-box; /* Safari */
    color: #333;
    margin-bottom: 40px;
    border-right:1px solid red;
  }

  .el-main {
    color: #333;
    padding: 0 0 40px 60px;
  }

  .el-container {
    background-color: #ffffff;
    margin-top: 23px;
    margin-bottom: 40px;
  }

  .info-title {
    margin-bottom: 10px;
    font-family: PingFang-SC-Semibold;
    font-size: 20px;
    color: #000000;
    letter-spacing: 0;
    text-align: left;
    font-weight: bold;
  }

  .paid-title {
    display:inline-block;
    line-height: 20px;
    font-family:PingFang-SC-Semibold;
    font-size:16px;
    color:#72bd1e;
    letter-spacing:0;
    float:right;
  }

  .unpaid-title {
    display:inline-block;
    line-height: 20px;
    font-family:PingFang-SC-Semibold;
    font-size:16px;
    color:#c8c8c8;
    letter-spacing:0;
    float:right;
  }
  .unpaid-title span{
    color:#ff2828;
  }

  .total-title {
    display:inline-block;
    line-height: 20px;
    font-family:PingFang-SC-Semibold;
    font-size:16px;
    color:#000000;
    letter-spacing:0;
    float:right;
  }

  .total-title span{
    color:#ff2828;
  }

  .add-pay-btn {
    margin-top: 16px;
    text-align: center;
  }

  .add-pay-btn button {
    border: none;
    background:#ff8214;
    border-radius:5px;
    width:320px;
    height:40px;
  }

</style>
